<?php

require_once( dirname(__FILE__).'/../libs/db.php' );
require_once( dirname(__FILE__).'/../appdata/structures.php' );
require_once( dirname(__FILE__).'/../libs/bedmintonlib.php' );

$tournament = "Turnaje";
$tourDescription = "Momentálne sa žiadne turnaje nekonajú.";

if (isEnglish())

$tournament = "Tournaments";
$tourDescription = "There are no tournaments at the moment.";
    
$db = Db::db();
$dbConnection = $db->connection();
if (is_null( $dbConnection ))
{
    // $outMessage = $db->getErrorStr();
    return;
}

try
{
    $statement = $dbConnection->prepare( "SELECT id, tournamentdate, description FROM tournaments WHERE tournamentdate >= current_date ORDER BY tournamentdate");
    $statement->execute();
    $result = $statement->fetchAll( PDO::FETCH_NUM );
    if (! $result)
        exit;
    
    $isEmpty = true;
    $resultStr = "<table>";
    foreach($result as $row)
    {
        $date = MyDateTime::fromPqDate( $row[1] );
        $paramDate = $date->toPqDate();
        $printDate = $date->toDate();
        $resultStr .= "<tr><td>";
        $resultStr .= "<div class =\"linkDescription\"><a href=\"index.php?siteName=mainsites/reservation.php&amp;reservationDate=$paramDate\">$printDate - $row[2]</a></div>";
        $resultStr .= "</td></tr>";
        $isEmpty = false;
    }
    $resultStr .= "</table>";
}
catch(PDOException $e)
{
    exit;
}

echo( "<div class=\"mainSitesTitle\">$tournament</div>" );

if ($isEmpty)
{
    echo( "<div>$tourDescription</div>" );
}
else
{
    echo( "<div>$resultStr</div>" );
}




?>
